using UnityEngine;

public class MyDataManager : MonoSingleton<MyDataManager>
{
	private SO_Data_Player _mData_玩家基础;

	private SO_Data_Player招式 _mData_玩家招式;

	private SO_Data_Scene _mData_Scene;

	private SO_Data_Enemy _mData_Enemy;

	public PlayerItemDataInfo _mPlayerData;

	public bool _第一次 = true;

	public PlayerItemDataInfo _PlayerData
	{
		get
		{
			if (_mPlayerData == null)
			{
				F_读取数据();
			}
			if (_第一次)
			{
				_第一次 = false;
				F_读取数据();
			}
			return _mPlayerData;
		}
		private set
		{
			_mPlayerData = value;
		}
	}

	public int _玩家等级
	{
		get
		{
			if (_PlayerData._Player等级 == -1)
			{
				return _Data_玩家基础._初始等级;
			}
			return _PlayerData._Player等级;
		}
		set
		{
			_PlayerData._Player等级 = value;
		}
	}

	public SO_Data_Player _Data_玩家基础
	{
		get
		{
			if (_mData_玩家基础 == null)
			{
				_mData_玩家基础 = Resources.Load<SO_Data_Player>("SOData/PlayerData");
			}
			return _mData_玩家基础;
		}
	}

	public SO_Data_Player招式 _Data_玩家招式
	{
		get
		{
			if (_mData_玩家招式 == null)
			{
				_mData_玩家招式 = Resources.Load<SO_Data_Player招式>("SOData/PlayerData招式");
			}
			return _mData_玩家招式;
		}
	}

	public SO_Data_Scene _Data_Scene
	{
		get
		{
			if (_mData_Scene == null)
			{
				_mData_Scene = Resources.Load<SO_Data_Scene>("SOData/SceneLinkData");
			}
			return _mData_Scene;
		}
	}

	public SO_Data_Enemy _Data_Enemy
	{
		get
		{
			if (_mData_Enemy == null)
			{
				_mData_Enemy = Resources.Load<SO_Data_Enemy>("SOData/EnemyData");
			}
			return _mData_Enemy;
		}
	}

	private void Start()
	{
		_ = _Data_玩家基础 == null;
		_ = _Data_玩家招式 == null;
		_ = _Data_Scene == null;
		_ = _Data_Enemy == null;
		F_读取数据();
	}

	public void F_读取数据()
	{
		if (PlayerPrefs.HasKey("PlayerData"))
		{
			string @string = PlayerPrefs.GetString("PlayerData");
			Debug.LogError(@string);
			_mPlayerData = JsonUtility.FromJson<PlayerItemDataInfo>(@string);
		}
		else
		{
			_mPlayerData = new PlayerItemDataInfo();
		}
	}

	public void F_保存数据()
	{
		if (_mPlayerData == null)
		{
			_mPlayerData = new PlayerItemDataInfo();
		}
		string text = JsonUtility.ToJson(_mPlayerData);
		Debug.LogError("DataInfo:" + text);
		PlayerPrefs.SetString("PlayerData", text);
		PlayerPrefs.Save();
	}

	public void F_上香(int 上香地图ID)
	{
		Debug.LogError($"上香地点<<{上香地图ID}>>");
		if (_Data_Scene.F_MapPonit_上香_是否存在(上香地图ID))
		{
			_PlayerData._上香地图ID = 上香地图ID;
			F_保存数据();
		}
		else
		{
			Debug.LogError($"没有<<{上香地图ID}>>土地庙");
		}
	}

	public void F_重置数据()
	{
		_mPlayerData = new PlayerItemDataInfo();
		PlayerPrefs.SetFloat("游戏时长", 0f);
		MonoSingleton<GameManager>.Instance._GameTime = 0f;
		F_保存数据();
	}

	public void F_敲钟(int 钟id)
	{
		if (钟id >= 0 && 钟id < _PlayerData._钟1.Length)
		{
			_PlayerData._钟1[钟id] = true;
			F_保存数据();
		}
		else
		{
			Debug.LogError($"敲钟失败<<{钟id}>>");
		}
	}

	public void F_击败Boss(string bossName)
	{
		for (int i = 0; i < _PlayerData._List_Name_Bool.Count; i++)
		{
			if (_PlayerData._List_Name_Bool[i]._BossName == bossName)
			{
				_PlayerData._List_Name_Bool[i]._已击败 = true;
				MonoSingleton<GameManager>.Instance.F_显示得胜(bossName);
				F_保存数据();
				return;
			}
		}
		Debug.LogError("击败Bosss失败<<" + bossName + ">>");
	}

	public bool F_判断Boss是否已经击败(string bossName)
	{
		bool result = true;
		foreach (PlayerItemDataInfo_Boss击败记录 item in _PlayerData._List_Name_Bool)
		{
			if (item._BossName == bossName)
			{
				return item._已击败;
			}
		}
		return result;
	}
}
